home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 November / CPNL0711.ISO / boekhoud / finan / BADGER finance v1.0 beta 2.exe / xampplite / phpMyAdmin / libraries / db_table_exists.lib.php < prev    next >
PHP Script  |  2006-04-12  |  3KB  |  75 lines

  1. <?php
  2. /* $Id: db_table_exists.lib.php,v 2.11.2.2 2006/04/12 18:51:11 lem9 Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. /**
  6.  * Ensure the database and the table exist (else move to the "parent" script)
  7.  * and display headers
  8.  */
  9. if (empty($is_db)) {
  10.     if (isset($db) && strlen($db)) {
  11.         $is_db = @PMA_DBI_select_db($db);
  12.     } else {
  13.         $is_db = false;
  14.     }
  15.  
  16.     if (! $is_db) {
  17.         // not a valid db name -> back to the welcome page
  18.         if (! defined('IS_TRANSFORMATION_WRAPPER')) {
  19.             $url_params = array('reload' => 1);
  20.             if (isset($message)) {
  21.                 $url_params['message'] = $message;
  22.             }
  23.             PMA_sendHeaderLocation(
  24.                 $cfg['PmaAbsoluteUri'] . 'main.php'
  25.                     . PMA_generate_common_url($url_params, '&'));
  26.         }
  27.         exit;
  28.     }
  29. } // end if (ensures db exists)
  30.  
  31. if (empty($is_table)) {
  32.     // Not a valid table name -> back to the db_details.php
  33.     if (isset($table) && strlen($table)) {
  34.         $_result = PMA_DBI_try_query(
  35.             'SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, true) . '\';',
  36.             null, PMA_DBI_QUERY_STORE);
  37.         $is_table = @PMA_DBI_num_rows($_result);
  38.         PMA_DBI_free_result($_result);
  39.     } else {
  40.         $is_table = false;
  41.     }
  42.  
  43.     if (! $is_table) {
  44.         if (! defined('IS_TRANSFORMATION_WRAPPER')) {
  45.             if (isset($table) && strlen($table)) {
  46.                 // SHOW TABLES doesn't show temporary tables, so try select
  47.                 // (as it can happen just in case temporary table, it should be
  48.                 // fast):
  49.  
  50.                 // @todo should this check really only happen if IS_TRANSFORMATION_WRAPPER?
  51.                 $_result = PMA_DBI_try_query(
  52.                     'SELECT COUNT(*) FROM `' . PMA_sqlAddslashes($table, true) . '`;',
  53.                     null, PMA_DBI_QUERY_STORE);
  54.                 $is_table = ($_result && @PMA_DBI_num_rows($_result));
  55.                 PMA_DBI_free_result($_result);
  56.             }
  57.  
  58.             if (! $is_table) {
  59.                 $url_params = array('reload' => 1, 'db' => $db);
  60.                 if (isset($message)) {
  61.                     $url_params['message'] = $message;
  62.                 }
  63.                 PMA_sendHeaderLocation(
  64.                     $cfg['PmaAbsoluteUri'] . 'db_details.php'
  65.                         . PMA_generate_common_url($url_params, '&'));
  66.             }
  67.         }
  68.  
  69.         if (! $is_table) {
  70.             exit;
  71.         }
  72.     }
  73. } // end if (ensures table exists)
  74. ?>
  75.